package com.hsy.bibc.modules.main.actionbars;

import android.content.Context;
import android.content.Intent;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.hsy.bibc.R;
import com.hsy.bibc.modules.main.MainActivity;
import com.hsy.bibc.modules.order.OrderActivity;

/**
 * Created by hsy on 2016/4/7.
 */
public class ActionBarMain extends RelativeLayout implements IActionBar, View.OnClickListener {
    protected View rootView;
    protected TextView mGarbage, home_title;
    protected TextView mExchange;
    protected TextView mOrder;
    protected TextView mGathering;
    private MainActivity activity;

    public ActionBarMain(Context context) {
        super(context);
        init(context);
    }

    public ActionBarMain(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context);
    }

    public ActionBarMain(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context);
    }

    @Override
    public void setActivity(MainActivity activity) {
        this.activity = activity;
    }

    private void init(Context context) {
        rootView = inflate(context, R.layout.actionbar_home, null);
        addView(rootView, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));

        initView(rootView, context);
    }

    private void initView(View rootView, Context context) {
        mGarbage = (TextView) rootView.findViewById(R.id.qr_scan);
        mExchange = (TextView) rootView.findViewById(R.id.exchange);
        mGathering = (TextView) rootView.findViewById(R.id.gathering);
        mOrder = (TextView) rootView.findViewById(R.id.order);
        mOrder.setOnClickListener(ActionBarMain.this);

        home_title = (TextView) rootView.findViewById(R.id.home_title);
    }

    @Override
    public void onClick(View view) {
        Intent intent = new Intent();
//        if (view.getId() == R.id.qr_scan) {
//            intent.setClass(activity, MipcaActivityCapture.class);
//            intent.putExtra(Consts.Keys.FROM_WHERE, "0");
//            activity.startActivity(intent);
//        } else if (view.getId() == R.id.exchange) {
//            activity.startActivity(new Intent(activity, ExChangeActivity.class));
//        } else
        if (view.getId() == R.id.order) {
            activity.startActivity(OrderActivity.class, "no commitOk");
//        } else if (view.getId() == R.id.gathering) {
//            intent.setClass(activity, MipcaActivityCapture.class);
//            intent.putExtra(Consts.Keys.FROM_WHERE, "1");
//            activity.startActivity(intent);
        }
    }
}
